home *** CD-ROM | disk | FTP | other *** search
- /* Copyright 1996 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* polygon_offset.c - draw a solid polygon with an outline.
- *
- * <p> Key - toggle polygon offset extension on/off
- * Escape Key - exit program
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <stdio.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
-
- void printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( (width / 2) + 4, height / 4 );
- glutInitWindowSize( (width / 2) - 4, height / 2 );
- glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutReshapeFunc( reshape );
- glutKeyboardFunc( keyboard );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- void
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - demonstrates depth buffering\n\n"
- "<p> Key - toggle polygon offset on/off\n"
- "Escape Key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 0.5, 1.0 );
- glShadeModel( GL_FLAT );
-
- glEnable( GL_DEPTH_TEST );
-
- glLineWidth( 2.5 );
-
- #ifdef GL_EXT_polygon_offset
- if ( glutExtensionSupported( "GL_EXT_polygon_offset" )) {
- glPolygonOffsetEXT( 1.0, 0.00002 );
- }
- #endif
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height );
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- aspect = (GLdouble) width / (GLdouble) height;
- gluPerspective( 45.0, aspect, 3.0, 7.0 );
- glMatrixMode( GL_MODELVIEW );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- static GLboolean offsetPolygon = GL_FALSE;
- switch (key) {
- case 'p':
- #ifdef GL_EXT_polygon_offset
- offsetPolygon = !offsetPolygon;
- if ( offsetPolygon )
- glEnable( GL_POLYGON_OFFSET_EXT );
- else
- glDisable( GL_POLYGON_OFFSET_EXT );
- printf("polygon offset %s\n",
- (offsetPolygon? "Enabled":"Disabled"));
- #else
- printf("polygon offset not supported by client\n");
- #endif
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat fillColor[] = { 1.0, 1.0, 1.0 };
- static GLfloat outlineColor[] = { 0.0, 0.0, 0.0 };
-
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- glPushMatrix();
- /* Move origin between the near and far clipping planes */
- glTranslatef( 0.0, 0.0, -5.0 );
-
- glRotatef( 45.0, 1.0, 1.0, 1.0 );
-
- /* Draw a solid sphere with an outline */
- glColor3fv( fillColor );
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glutSolidSphere( 1.5, 15, 15 );
-
- glColor3fv( outlineColor );
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glutSolidSphere( 1.5, 15, 15 );
-
- glPopMatrix();
-
- glFlush();
- }
-